<style lang="scss" scoped>
.assessment-trauma {
  .assessment-title {
    font-size: 20px;
    font-weight: 400;
  }
}
</style>

<template>
  <div class="assessment-trauma">
    <el-tabs v-model="activeName" style="padding: 0 10px;">
      <el-tab-pane label="TI创伤评分" name="TIAssessment">
        <el-row type="flex" justify="end" style="padding-right: 40px">
          <el-button type="primary" @click="saveData('Ti')">保存</el-button>
        </el-row>
        <el-form label-width="120px" class="pageForm">
          <el-row>
            <el-col :span="24">
              <span class="assessment-title">TI创伤评分</span>
            </el-col>
            <el-col :span="24"><el-divider /></el-col>
            <el-col :span="24">
              <el-col :span="8">
                <el-form-item label="创伤部位">
                  <el-radio-group v-model="woundArea" @change="TiChange()">
                    <el-radio label="0">无</el-radio>
                    <el-radio label="1">肢体/皮肤</el-radio>
                    <el-radio label="3">背部</el-radio>
                    <el-radio label="5">胸腹部</el-radio>
                    <el-radio label="6">头颈部</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="创伤类型">
                  <el-radio-group v-model="traumaType" @change="TiChange()">
                    <el-radio label="0">无</el-radio>
                    <el-radio label="1">裂伤/挫伤</el-radio>
                    <el-radio label="3">刺伤</el-radio>
                    <el-radio label="5">钝性伤</el-radio>
                    <el-radio label="6">弹道伤</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="体表出血">
                  <el-radio-group v-model="surfaceBleeding" @change="TiChange()">
                    <el-radio label="0">无</el-radio>
                    <el-radio label="1">有</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-col>
            <el-col :span="24">
              <el-form-item label="循环情况">
                <el-radio-group v-model="circular" @change="TiChange()">
                  <el-radio label="0">无下述情况</el-radio>
                  <el-radio label="3">{{ '80≤收缩压<100(mmHg) /100<脉搏≤140(bpm)' }}</el-radio>
                  <el-radio label="5">{{ '收缩压<80(mmHg) /心率>140(bpm)' }}</el-radio>
                  <el-radio label="6">无脉搏</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="中枢神经系统">
                <el-radio-group v-model="centralNervous" @change="TiChange()">
                  <el-radio label="0">清醒</el-radio>
                  <el-radio label="1">嗜睡</el-radio>
                  <el-radio label="3">昏睡</el-radio>
                  <el-radio label="5">半昏迷</el-radio>
                  <el-radio label="6">昏迷</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="呼吸情况">
                <el-radio-group v-model="breathing" @change="TiChange()">
                  <el-radio label="0">正常</el-radio>
                  <el-radio label="1">胸痛</el-radio>
                  <el-radio label="3">呼吸困难/咯血</el-radio>
                  <el-radio label="5">误吸</el-radio>
                  <el-radio label="6">窒息/全身发绀</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-col :span="8">
                <el-form-item label="Ti创伤指数分数">
                  <el-input v-model="TiGrade" disabled size="mini">
                    <template #append>
                      <div class="label">{{ Number(TiGrade) < 8 ? "轻伤" : (Number(TiGrade) > 18) ? "严重伤" : "重伤" }}</div>
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="评测时间">
                  <el-date-picker
                    v-model="TiReviewTime"
                    format="yyyy-MM-dd HH:mm:ss"
                    size="mini"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    type="datetime"
                    placeholder=""
                  />
                </el-form-item>
              </el-col>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="GCS创伤评分" name="GCSAssessment">
        <el-row type="flex" justify="end" style="padding-right: 40px">
          <el-button type="primary" @click="saveData('GCS')">保存</el-button>
        </el-row>
        <el-form label-width="140px" class="pageForm">
          <el-row>
            <el-col :span="24">
              <span class="assessment-title">Gcs评分</span>
            </el-col>
            <el-col :span="24"><el-divider /></el-col>
            <el-col :span="24">
              <el-form-item label="Gcs眼部">
                <el-radio-group v-model="gcsEye" @change="GcsChange()">
                  <el-radio label="1">无睁眼</el-radio>
                  <el-radio label="2">疼痛刺激睁眼</el-radio>
                  <el-radio label="3">呼唤睁眼</el-radio>
                  <el-radio label="4">自发睁眼</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="Gcs语言">
                <el-radio-group v-model="gcsLanguage" @change="GcsChange()">
                  <el-radio label="1">无发音</el-radio>
                  <el-radio label="2">可发声</el-radio>
                  <el-radio label="3">可说出单词</el-radio>
                  <el-radio label="4">答非所问</el-radio>
                  <el-radio label="5">正常交谈</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="Gcs运动">
                <el-radio-group v-model="gcsMovement" @change="GcsChange()">
                  <el-radio label="1">无反应</el-radio>
                  <el-radio label="2">疼痛刺激肢体伸展</el-radio>
                  <el-radio label="3">疼痛刺激肢体弯曲</el-radio>
                  <el-radio label="4">疼痛刺激肢体回缩</el-radio>
                  <el-radio label="5">对疼痛刺激可定位</el-radio>
                  <el-radio label="6">按吩咐运动</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-col :span="8">
                <el-form-item label="GCS昏迷指数分值">
                  <el-input v-model="gcsGrade" disabled size="mini">
                    <template #append>
                      <div class="label">{{ Number(gcsGrade) < 3 ? "" : Number(gcsGrade) < 8 ? "严重昏迷" : (Number(gcsGrade)
                        < 13) ? "重度昏迷" : (Number(gcsGrade) < 15) ? "轻度昏迷" : "正常" }}</div>
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="评测时间">
                  <el-date-picker
                    v-model="gcsReviewTime"
                    format="yyyy-MM-dd HH:mm:ss"
                    size="mini"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    type="datetime"
                    placeholder=""
                  />
                </el-form-item>
              </el-col>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="ISS、AIS评分" name="AISAssessment">
        <el-row type="flex" justify="end" style="padding-right: 40px">
          <el-button type="primary" @click="saveData('ISS')">保存</el-button>
        </el-row>
        <el-form label-width="120px" class="pageForm">
          <el-row>
            <el-col :span="24">
              <span class="assessment-title">ISS、AIS评分</span>
            </el-col>
            <el-col :span="24"><el-divider /></el-col>
            <el-col :span="24">
              <el-form-item label="头颈部">
                <el-radio-group v-model="issHead" @change="IssChange()">
                  <el-radio label="1">1分：轻度</el-radio>
                  <el-radio label="2">2分：中度</el-radio>
                  <el-radio label="3">3分：重度不危及生命</el-radio>
                  <el-radio label="4">4分：重度危及生命</el-radio>
                  <el-radio label="5">5分：危重或可成活</el-radio>
                  <el-radio label="6">6分：最大损伤</el-radio>
                  <!-- <el-radio label="6">6分：碾压骨折、脑干碾压撕裂、断头、C3或C3以上骨折/脱位、颈髓裂伤或横断、心脏复杂性碎裂/撕脱</el-radio> -->
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="胸部">
                <el-radio-group v-model="issChest" @change="IssChange()">
                  <el-radio label="1">1分：轻度</el-radio>
                  <el-radio label="2">2分：中度</el-radio>
                  <el-radio label="3">3分：重度不危及生命</el-radio>
                  <el-radio label="4">4分：重度危及生命</el-radio>
                  <el-radio label="5">5分：危重或可成活</el-radio>
                  <el-radio label="6">6分：最大损伤</el-radio>
                  <!-- <el-radio label="6">6分：胸主动脉完全断离,胸部广泛碾压毁损</el-radio> -->
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="面部">
                <el-radio-group v-model="issFace" @change="IssChange()">
                  <el-radio label="1">1分：轻度</el-radio>
                  <el-radio label="2">2分：中度</el-radio>
                  <el-radio label="3">3分：重度不危及生命</el-radio>
                  <el-radio label="4">4分：重度危及生命</el-radio>
                  <el-radio label="5">5分：危重或可成活</el-radio>
                  <el-radio label="6">6分：最大损伤</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="腹部及盆腔">
                <el-radio-group v-model="issAbdomen" @change="IssChange()">
                  <el-radio label="1">1分：轻度</el-radio>
                  <el-radio label="2">2分：中度</el-radio>
                  <el-radio label="3">3分：重度不危及生命</el-radio>
                  <el-radio label="4">4分：重度危及生命</el-radio>
                  <el-radio label="5">5分：危重或可成活</el-radio>
                  <el-radio label="6">6分：最大损伤</el-radio>
                  <!-- <el-radio label="6">6分：躯干横断、肝脏横断、肝脏撕脱伤(所有血管完全断离)</el-radio> -->
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="四肢及骨盆">
                <el-radio-group v-model="issLimbs" @change="IssChange()">
                  <el-radio label="1">1分：轻度</el-radio>
                  <el-radio label="2">2分：中度</el-radio>
                  <el-radio label="3">3分：重度不危及生命</el-radio>
                  <el-radio label="4">4分：重度危及生命</el-radio>
                  <el-radio label="5">5分：危重或可成活</el-radio>
                  <el-radio label="6">6分：最大损伤</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="体表">
                <el-radio-group v-model="issSurface" @change="IssChange()">
                  <el-radio label="1">1分：轻度</el-radio>
                  <el-radio label="2">2分：中度</el-radio>
                  <el-radio label="3">3分：重度不危及生命</el-radio>
                  <el-radio label="4">4分：重度危及生命</el-radio>
                  <el-radio label="5">5分：危重或可成活</el-radio>
                  <el-radio label="6">6分：最大损伤</el-radio>
                  <!-- <el-radio label="6">6分：Ⅱ度或Ⅲ度烧伤/脱套伤≥90%体表面积</el-radio> -->
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-col :span="8">
                <el-form-item label="ISS创伤指数分值">
                  <el-input v-model="issGrade" disabled size="mini">
                    <template #append>
                      <div class="label">{{ Number(issGrade) >= 16 || Number(aisGrade) >= 3 ? "严重创伤病人" : Number(issGrade) <
                        16 && Number(aisGrade) < 3 ? "创伤病人" : "" }}</div>
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="评测时间">
                  <el-date-picker
                    v-model="issReviewTime"
                    format="yyyy-MM-dd HH:mm:ss"
                    size="mini"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    type="datetime"
                    placeholder=""
                  />
                </el-form-item>
              </el-col>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { findDiagnoses, diagnosesList } from '@/api/green-channel/assessmentTrauma'
import format from '@/utils/format'
export default {
  name: 'AssessmentTrauma',
  props: ['checkrowdata'],
  data() {
    return {
      activeName: 'TIAssessment',
      woundArea: '',
      traumaType: '',
      surfaceBleeding: '',
      circular: '',
      centralNervous: '',
      breathing: '',
      TiGrade: '',
      TiReviewTime: '',
      TiInfo: null,
      gcsEye: '',
      gcsLanguage: '',
      gcsMovement: '',
      gcsGrade: '',
      gcsReviewTime: '',
      gcsInfo: null,
      issHead: '',
      issChest: '',
      issFace: '',
      issAbdomen: '',
      issLimbs: '',
      issSurface: '',
      issGrade: '',
      aisGrade: '',
      issReviewTime: '',
      issInfo: null
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.cancle()
      findDiagnoses({
        dispatchId: this.checkrowdata.dispatchId
      }).then(res => {
        if (res && res.length > 0) {
          res.forEach(el => {
            if (el.diagnoseType == 'trauma_ti') {
              if (el.diagnoseContent) {
                const TiContent = el.diagnoseContent.split('|')
                console.log(TiContent, 'TiContent')
                this.woundArea = TiContent[0]
                this.traumaType = TiContent[1]
                this.surfaceBleeding = TiContent[2]
                this.circular = TiContent[3]
                this.centralNervous = TiContent[4]
                this.breathing = TiContent[5]
                this.TiChange()
              }
              this.TiReviewTime = el.diagnoseTime
              this.TiInfo = el
            }
            if (el.diagnoseType == 'trauma_gcs') {
              if (el.diagnoseContent) {
                const GcsContent = el.diagnoseContent.split('|')
                this.gcsEye = GcsContent[0]
                this.gcsLanguage = GcsContent[1]
                this.gcsMovement = GcsContent[2]
                this.GcsChange()
              }
              this.gcsReviewTime = el.diagnoseTime
              this.gcsInfo = el
            }
            if (el.diagnoseType == 'trauma_iss') {
              if (el.diagnoseContent) {
                const GcsContent = el.diagnoseContent.split('|')
                this.issHead = GcsContent[0]
                this.issChest = GcsContent[1]
                this.issFace = GcsContent[2]
                this.issAbdomen = GcsContent[3]
                this.issLimbs = GcsContent[4]
                this.issSurface = GcsContent[5]
                this.IssChange()
              }
              this.issReviewTime = el.diagnoseTime
              this.issInfo = el
            }
          })
        }
      })
    },
    TiChange() {
      this.TiGrade = Number(this.woundArea) + Number(this.traumaType) + Number(this.surfaceBleeding) + Number(this.circular) + Number(this.centralNervous) + Number(this.breathing)
    },
    GcsChange() {
      this.gcsGrade = Number(this.gcsEye) + Number(this.gcsLanguage) + Number(this.gcsMovement)
    },
    IssChange() {
      const asiArr = []
      asiArr.push(Number(this.issHead), Number(this.issChest), Number(this.issFace), Number(this.issAbdomen), Number(this.issAbdomen), Number(this.issSurface))
      const asiArrSort = asiArr.sort().reverse()
      this.aisGrade = asiArrSort[0]
      if (asiArrSort[0] === 6) {
        this.issGrade = 75
      } else {
        this.issGrade = Math.pow(asiArrSort[0], 2) + Math.pow(asiArrSort[1], 2) + Math.pow(asiArrSort[2], 2)
        if (this.issGrade > 75) {
          this.issGrade = 75
        }
      }
    },
    saveData(type) {
      let assessArr = []
      const nowTime = format(new Date(), 'YYYY-MM-DD HH:mm:ss')
      if (type == 'Ti') {
        const TiContent = [
          this.woundArea,
          this.traumaType,
          this.surfaceBleeding,
          this.circular,
          this.centralNervous,
          this.breathing
        ]
        assessArr = [{
          createdAt: this.TiInfo.createdAt,
          department: this.TiInfo.department,
          diagnoseContent: TiContent.join('|'),
          diagnoseName: null,
          diagnoseTime: this.TiReviewTime,
          diagnoseType: 'trauma_ti',
          dispatchId: this.checkrowdata.dispatchId,
          grade: null,
          id: this.TiInfo.id,
          killipLevel: null,
          medicalId: this.checkrowdata.medicalId,
          remarks: this.TiInfo.remarks,
          score: this.TiGrade,
          strokeDiagnosisName: null,
          strokeDiagnosisType: null,
          updatedAt: nowTime,
          user: this.TiInfo.user,
          userId: this.checkrowdata.userId
        }]
      } else if (type == 'GCS') {
        const GcsContent = [
          this.gcsEye,
          this.gcsLanguage,
          this.gcsMovement
        ]
        assessArr = [{
          createdAt: this.gcsInfo.createdAt,
          department: this.gcsInfo.department,
          diagnoseContent: GcsContent.join('|'),
          diagnoseName: null,
          diagnoseTime: this.gcsReviewTime,
          diagnoseType: 'trauma_gcs',
          dispatchId: this.checkrowdata.dispatchId,
          grade: null,
          id: this.gcsInfo.id,
          killipLevel: null,
          medicalId: this.checkrowdata.medicalId,
          remarks: this.gcsInfo.remarks,
          score: this.gcsGrade,
          strokeDiagnosisName: null,
          strokeDiagnosisType: null,
          updatedAt: nowTime,
          user: this.gcsInfo.user,
          userId: this.checkrowdata.userId
        }]
      } else if (type == 'ISS') {
        const IssContent = [
          this.issHead,
          this.issChest,
          this.issFace,
          this.issAbdomen,
          this.issLimbs,
          this.issSurface
        ]
        assessArr = [{
          createdAt: this.issInfo.createdAt,
          department: this.issInfo.department,
          diagnoseContent: IssContent.join('|'),
          diagnoseName: null,
          diagnoseTime: this.issReviewTime,
          diagnoseType: 'trauma_iss',
          dispatchId: this.checkrowdata.dispatchId,
          grade: null,
          id: this.issInfo.id,
          killipLevel: null,
          medicalId: this.checkrowdata.medicalId,
          remarks: this.issInfo.remarks,
          score: this.issGrade,
          strokeDiagnosisName: null,
          strokeDiagnosisType: null,
          updatedAt: nowTime,
          user: this.issInfo.user,
          userId: this.checkrowdata.userId
        }]
      }
      console.log(assessArr, 'assessArr')
      diagnosesList(assessArr).then(res => {
        if (res.code == 0) {
          this.$message({
            type: 'success',
            message: '保存成功'
          })
          this.init()
        }
      })
    },
    cancle() {
      this.woundArea = '',
      this.traumaType = '',
      this.surfaceBleeding = '',
      this.circular = '',
      this.centralNervous = '',
      this.breathing = '',
      this.TiGrade = '',
      this.TiReviewTime = '',
      this.TiInfo = null,
      this.gcsEye = '',
      this.gcsLanguage = '',
      this.gcsMovement = '',
      this.gcsGrade = '',
      this.gcsReviewTime = '',
      this.gcsInfo = null,
      this.issHead = '',
      this.issChest = '',
      this.issFace = '',
      this.issAbdomen = '',
      this.issLimbs = '',
      this.issSurface = '',
      this.issGrade = '',
      this.issReviewTime = '',
      this.issInfo = null
    }
  }
}
</script>

